package com.tianfei.crowd.controller;


import com.tianfei.crowd.entity.po.MemberPO;
import com.tianfei.crowd.service.api.MemberService;
import com.tianfei.crowd.utils.ResultEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Mysql端本地的controller： 提供给 Member 微服务远程调用的 controller
 *
 * @author: Herz
 * @date: 2021/7/27 20:41
 */
@RestController
public class MemberProviderController {

    @Autowired
    MemberService memberService;

    @RequestMapping("/save/member/remote")
    public ResultEntity<String> saveMemberRemote(@RequestBody MemberPO memberPO) {

        // 执行保存
        memberService.saveMember(memberPO);

        // 保存成功
        return ResultEntity.successWithOutData();
    }


    @RequestMapping("/get/member/by/login/acct/remote")
    public ResultEntity<MemberPO> getMemberPOByLoginAcctRemote(@RequestParam("loginacct") String loginacct) {

        try {
            // 1、调用本地的 Service 执行查询
            MemberPO memberPO = memberService.getMemberPOByLoginAcct(loginacct);

            // 2、查询成功返回 查询结果
            return ResultEntity.successWithData(memberPO);
        } catch (Exception e) {
            // 3、查询失败，返回异常信息
            return ResultEntity.failed(e.getMessage());
        }
    }
}
